#makefile
PARAM_FILE:=../Makefile.param
include $(PARAM_FILE)

CC = $(CROSS_COMPILE)gcc
RANLIB = $(CROSS_COMPILE)ranlib
AR = $(CROSS_COMPILE)ar

CFLAGS := -g -O2 -D_REENTRANT -Wall
LIBS := -lpthread
OBJ_NAME := libmylib
SOURCE := $(wildcard *.c)
OBJS := $(patsubst %.c,%.o,$(SOURCE))
OUT_DIR := ../obj/$(PROJ)/
CLEANFILES := *.o *.so *.a


%.o:%.c mylib.h
	$(CC) -c -o $@ $< $(CFLAGS)


.PHONY:all
all: $(OUT_DIR)$(OBJ_NAME).so $(OUT_DIR)$(OBJ_NAME).a

$(OUT_DIR)$(OBJ_NAME).so:$(OBJS)
	@if [ -e $(OUT_DIR) ] ;\
	 then echo "$(OUT_DIR) exists - good." ;\
        else mkdir -p $(OUT_DIR);\
        fi;
	$(CC) -o $@ -fPIC -shared $^ $(LIBS)
	
$(OUT_DIR)$(OBJ_NAME).a:$(OBJS)
#	@if [ -e $(OUT_DIR) ] ;\
#	 then echo "$(OUT_DIR) exists - good." ;\
#      else mkdir -p $(OUT_DIR);\
#      fi;
	$(AR) rv $@ $?
	$(RANLIB) $@
	cp *.h $(OUT_DIR)

install:
	@if [ -e $(INSTALL_DIR) ] ;\
	 then echo "$(INSTALL_DIR) exists - good." ;\
        else mkdir -p $(INSTALL_DIR);\
        fi;	
	cd $(OUT_DIR);cp *.so *a $(INSTALL_DIR);cp *.so *a $(TFTP_BOOT); cp *.h $(INCLUDE_DIR)
	
	
clean:
	rm -f $(CLEANFILES)
